<template>
  <div class="analysis-table">
    <!-- <div class="name">
      <span>交叉(卡方)</span>
      <span>
        <el-select v-model="chiSquareValue" style="width: 200px">
          <el-option label="数字(占比)" value="1" />
          <el-option label="数字" value="2" />
          <el-option label="百分比" value="3" />
        </el-select>
      </span>
    </div> -->
    <div style="box-shadow: 0 0 10px #ccc; padding: 10px; margin: 10px 0; border-radius: 5px">
      <table style="width: 100%" v-if="currentData" id="score">
        <thead>
          <tr>
            <th :colspan="5">频数分析结果</th>
          </tr>
          <tr>
            <th rowspan="1" colspan="1">名称</th>
            <th rowspan="1" colspan="1">选项</th>
            <th rowspan="1" colspan="1">频数</th>
            <th rowspan="1" colspan="1">百分比(%)</th>
            <th rowspan="1" colspan="1">累积百分比(%)</th>
          </tr>
        </thead>
        <tbody>
          <template v-for="(item, index) in currentData.items" :key="index">
            <tr v-for="(i, index) in item.options" :key="index">
              <td v-if="index === 0" :rowspan="item.options.length">{{ item.name }}</td>
              <td>{{ i.optionDesc }}</td>
              <td>{{ i.frequency }}</td>
              <td>{{ (i.ratio * 100).toFixed(2) }}</td>
              <td>{{ (i.accumulate * 100).toFixed(2) }}</td>
            </tr>
          </template>
          <tr>
            <td colspan="2">合计</td>
            <td>{{ currentData.totalRecords }}</td>
            <td>100</td>
            <td>100</td>
          </tr>
        </tbody>
      </table>
    </div>
    <div>
      <slot name="analysis"></slot>
    </div>
  </div>
</template>

<script setup>
import { onMounted } from 'vue-demi'

const chiSquareValue = ref('1')
const tableData = ref([])
const selectValue = ref('1')
const prop = defineProps({
  data: {
    type: Object,
    default: () => ({})
  }
})
const currentData = ref('')
onMounted(() => {
  console.log(prop.data)
  setData()
})
const setData = () => {
  const data = JSON.parse(JSON.stringify(prop.data))
  data.items.forEach((item) => {
    item.options.forEach((i, index) => {
      if (index == 0) {
        i.accumulate = i.ratio
      } else {
        i.accumulate = i.ratio + item.options[index - 1].accumulate
      }
    })
  })
  currentData.value = data
}
</script>

<style lang="scss" scoped>
.name {
  padding: 20px;
  text-align: center;
  font-size: 20px;
  font-weight: 700;
}
.entropyChange {
  margin-left: 10px;
  border: 1px solid #000;
  cursor: pointer;
}
</style>
<style lang="scss">
.analysis-table {
  table {
    /* width: 100%; */
    /* border: 1px solid #DDDDDD; */
    /* width: 1137px; */
    border-collapse: collapse;
    font-size: 14px;
    background-color: #fff;
    margin-bottom: 10px;
  }

  table tr {
    width: 100%;
    /* line-height: 35px; */
    height: 27px;
    /* height: 35px; */
    text-align: center;
  }

  table tr th {
    /* background: #fafafa; */
    color: #000;
    font-weight: 400;
    /* border: 1px solid #DDDDDD; */
    line-height: 30px;
    text-align: center;
    border-bottom: 1px solid;
  }

  table tr td {
    color: #000;
    /* border: 1px solid #DDDDDD; */
    /* border-bottom: 2px solid; */
  }
}
</style>
